package com.ffz.springbootvuedemo.util;

import com.ffz.springbootvuedemo.bean.Result;

/**
 * @description:
 * @author: fengfazheng
 * @create: 2021-12-26 23:38
 **/
public class ResultUtils {
    public static Result resultOk() {
        return resultOk(null);
    }

    public static <T extends Result> T resultOk(Object data) {
        return resultOk(data, "操作成功");
    }

    public static <T extends Result> T resultOk(Object data, String msg) {
        Result result = new Result();
        result.setStatus(Result.OK);
        result.setMessage(msg);
        result.setData(data);
        return (T) result;
    }

    public static Result resultFail() {
        return resultFail("操作失败");
    }

    public static Result resultFail(String msg) {
        Result result = new Result();
        result.setStatus(Result.FAIL);
        result.setMessage(msg);
        return result;
    }

    public static Result resultFail(int code, String msg) {
        Result result = new Result();
        result.setStatus(code);
        result.setMessage(msg);
        return result;
    }
}